package com.gun.controller;

/**
 * @Authar: 吾图南
 * @Data: 2022/12/10 19:13
 * @Package: com.gun.controller
 * @ClassName: CommentController
 * @Description: TODO
 */

import com.gun.domain.Comment;
import com.gun.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     *
     * @param comment_id 每一条评论的主键id
     * @return 查询到的 评论
     */
    @GetMapping("/get/{id}")
    public Comment findById(@PathVariable("id") int comment_id){

        Comment comment = commentService.findById(comment_id);
        return comment;
    }

    @GetMapping("/update/{id}/{author}")
    public Comment updateComment(@PathVariable("id") int comment_id,
                                 @PathVariable("author") String author){
        Comment comment = commentService.findById(comment_id);
        //对象重新设置
        comment.setAuthor(author);
        Comment updateComment = commentService.updateComment(comment);

        return updateComment;
    }

    @GetMapping("/delete/{id}")
    public void deleteComment(@PathVariable("id") int comment_id){
        commentService.deleteComment(comment_id);
    }
}


